<template>
    <view>
        <view class="daya_list_header" :style="'background-color:' + color + ';'">
            <view @tap="tabClick" :class="'list_title ' + (activeIndex == index ? 'selsect' : 'default')" :id="index" v-for="(item, index) in tabs" :key="index">
                <view>{{ item }}</view>

                <view class="list_border" v-if="activeIndex == index"></view>
            </view>
        </view>
        <view class="main">
            <block v-if="activeIndex == 0">
                <view class="sjhb" v-for="(item, index) in ptarr" :key="index">
                    <view class="sjhbtop flex-row flex-y-center">
                        <view class="flex-grow-1 flex-col">
                            <view class="flex-grow-1 yhname">{{ item.name }}</view>
                            <view class="flex-grow-1 yhtype" v-if="item.coupon_type == '1'">店外可用</view>
                            <view class="flex-grow-1 yhtype" v-if="item.coupon_type == '2'">店内可用</view>
                            <view class="flex-grow-1 yhtype" v-if="item.coupon_type == '3'">店内店外</view>
                            <view class="flex-grow-1 yhtime">有效期至：{{ item.end_time }}</view>
                        </view>
                        <view class="flex-grow-0 flex-col flex-y-center">
                            <view class="flex-grow-1 yhmoney">￥{{ item.reduce }}</view>
                            <view class="flex-grow-1 yhtj">满{{ item.full }}可用</view>
                        </view>
                    </view>

                    <view class="sjhbbtm">
                        <view class="hyuan1"></view>
                        <view class="hyuan2"></view>
                        <view class="flex-grow-1 sysm">
                            {{ item.instruction }},
                            <text v-if="item.type_name.length > 0">
                                限
                                <text v-for="(item, index1) in item.type_name" :key="index1">{{ item }},</text>
                                类商家使用。
                            </text>
                        </view>
                    </view>
                </view>
                <view class="list_imgbk2" v-if="ptarr.length == 0">
                    <image class="list_imgbk" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/list.png"></image>
                    <view class="list_imgbk3" style="margin-top: -10rpx">您暂时还没有平台红包哦！</view>
                </view>
            </block>
            <block v-if="activeIndex == 1">
                <view class="sjhb" v-for="(item, index) in sjarr" :key="index">
                    <view class="sjhbtop flex-row flex-y-center">
                        <view class="mdlogo flex-row flex-y-center">
                            <image :src="item.logo"></image>
                        </view>
                        <view class="flex-grow-1 flex-col">
                            <view class="flex-grow-1 yhname">{{ item.store_name }}</view>
                            <view class="flex-grow-1 yhtype" v-if="item.coupon_type == '1'">店外可用</view>
                            <view class="flex-grow-1 yhtype" v-if="item.coupon_type == '2'">店内可用</view>
                            <view class="flex-grow-1 yhtype" v-if="item.coupon_type == '3'">店内店外</view>
                            <view class="flex-grow-1 yhtime">有效期至：{{ item.end_time }}</view>
                        </view>
                        <view class="flex-grow-0 flex-col flex-y-center">
                            <view class="flex-grow-1 yhmoney">￥{{ item.reduce }}</view>
                            <view class="flex-grow-1 yhtj">满{{ item.full }}可用</view>
                        </view>
                    </view>

                    <view class="sjhbbtm">
                        <view class="hyuan1"></view>
                        <view class="hyuan2"></view>
                        <view class="flex-grow-1 sysm">{{ item.instruction }}</view>
                        <view @tap="qsy" class="flex-grow-0 qsy" :data-sjid="item.store_id">去使用></view>
                    </view>
                </view>
                <view class="list_imgbk2" v-if="sjarr.length == 0">
                    <image class="list_imgbk" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/list.png"></image>
                    <view class="list_imgbk3" style="margin-top: -10rpx">您暂时还没有商家红包哦！</view>
                </view>
            </block>
        </view>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            tabs: ['平台红包', '商家红包'],
            activeIndex: 0,
            ptarr: '',
            sjarr: '',
            color: ''
        };
    },
    onLoad: function (t) {
        app.globalData.setNavigationBarColor(this);
        //console.log(this);
        var that = this;
        var a = uni.getStorageSync('users').id;
        app.globalData.util.request({
            url: 'entry/wxapp/MyCoupons',
            cachetime: '0',
            data: {
                user_id: a
            },
            success: function (t) {
                console.log(t.data);
                for (var a = [], e = [], n = 0; n < t.data.length; n++) {
                    if ('2' == t.data[n].type) {
                        a.push(t.data[n]);
                    }
                    if ('1' == t.data[n].type) {
                        e.push(t.data[n]);
                    }
                }
                console.log(a, e);
                that.setData({
                    ptarr: a,
                    sjarr: e
                });
            }
        });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    methods: {
        tabClick: function (t) {
            this.setData({
                activeIndex: t.currentTarget.id
            });
        },

        qsy: function (t) {
            console.log(t.currentTarget.dataset.sjid);
            getApp().globalData.sjid = t.currentTarget.dataset.sjid;
            uni.redirectTo({
                url: '/ymq_canyino2o/pages/seller/index'
            });
        }
    }
};
</script>
<style>
@import './myyhq.css';
</style>
